package agh.sr.lab4.bank.server;

import Ice.Current;
import Ice.LocalObjectHolder;
import Ice.Object;
import Ice.UserException;

public class BankOneToManyServantLocator extends BankAbstractServantLocator {

	private BankAccountI bankAccountServant = new BankAccountI();

	@Override
	public synchronized Object locate(Current curr, LocalObjectHolder cookie)
			throws UserException {
		System.out.println("============================");
		System.out.println("BankOneToManyServantLocator.locate()");
		System.out.println("id.category: " + curr.id.category);
		System.out.println("id.name: " + curr.id.name);
		System.out.println("curr.operation: " + curr.operation);
		System.out.println("============================");

		String pesel = curr.id.name;
		if (curr.operation.equalsIgnoreCase("login")) {
			if (!accountDataProvider.doesAccountExist(pesel)) {
				System.err.println("Account do not exist: " + pesel);
				return null;
			}
		}

		return bankAccountServant;
	}

}
